import { EMessageType } from "@/enums/messageType.enum.ts";

export interface IMessage {
  type: EMessageType;
  username: string;
  content?: string;
}

export class Message implements IMessage {
  type: EMessageType;
  username: string;
  content?: string;
  constructor(obj: IMessage) {
    this.type = obj.type;
    this.username = obj.username;
    this.content = obj.content;
  }
  toJsonString() {
    return JSON.stringify(this);
  }
  static toJsonObj(obj: string): IMessage {
    return JSON.parse(obj);
  }
}
